{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# RANSAC\n",
    "## 基本用途\n",
    "在样本噪音过多的情况下，依据单一模型，拟合更多的数据样本，减少噪音的影响。\n",
    "## 步骤\n",
    "1. 指定拟合模型\n",
    "2. 指定迭代次数\n",
    "3. 指定样本偏差\n",
    "4. 指定拟合样本阈值\n",
    "5. 随机选取几个样本点进行模型拟合\n",
    "6. 收集拟合偏差范围内样本点，记录拟合模型和拟合样本\n",
    "7. 如果拟合样本高于之前记录，更新拟合模型和样本数据\n",
    "8. 迭代次数内，重复5～8步骤\n",
    "9. 如果拟合样本数据高于指定拟合样本阈值，返回模型，否则返回None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 样本数据生成"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAD4CAYAAAAJmJb0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAUeklEQVR4nO3df6zddX3H8efbiuZOyS6MIu2ltehqs2LN6m6Izv1wAQWJo7XGpS6ZNZI0JpDpHzqoJMbEkOLIWLJM57pJxhaUkQilcSKC0ZglQ2z5XUqlikpvEepMxcUGBd/743wvnF7O6f1+7znf8+N7no/k5p7z/Z7z/X7u9/S++r3v8/5+TmQmkqRmetmwByBJqo8hL0kNZshLUoMZ8pLUYIa8JDXYy4c9gHZnnHFGrlmzZtjDkKSxsm/fvp9m5vJO60Yq5NesWcPevXuHPQxJGisR8aNu6yzXSFKDGfKS1GCGvCQ1mCEvSQ1myEtSg41Ud40kTZrd981x7R0HOXLsOCunp/j4hevYvHGmb9s35CVpSHbfN8eOWx7i+K+fB2Du2HF23PIQQN+C3nK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Z1eXFcHqD15vUf1j2uk70uwz5mxX5/i1Zo/3bbsoEfM1r/yTwJ/LrIr0u7ZVEdv4tOayBJDdaUco0kqQNDXpIazJCXpAYz5CWpwQx5SWowQ16SGsyQl6QG+384hxYnH8ZbtAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from numpy.linalg import cholesky\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "X = np.linspace(-10, 10, 30)\n",
    "Y = 3 * X - 5\n",
    "\n",
    "def offset(_Y):\n",
    "    return _Y + np.random.randint(-3, 3, _Y.shape)\n",
    "\n",
    "off_Y = offset(Y)\n",
    "basic_data = np.array([X, off_Y]).T\n",
    "plt.scatter(X, off_Y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  3.96265996 -14.69789992]\n",
      " [  4.68601461  -2.684169  ]\n",
      " [  1.7226401  -20.61908889]\n",
      " [  7.73655745  10.30642914]\n",
      " [  5.64019174  -1.26608566]\n",
      " [  0.6046754   -0.28015224]\n",
      " [ -2.54180524 -12.82548753]\n",
      " [  0.46677679  -2.63765126]\n",
      " [-11.6961749   -0.94443418]\n",
      " [ -4.5146914   -3.9859671 ]]\n"
     ]
    }
   ],
   "source": [
    "def noise(count):\n",
    "    mu = [0, -5]\n",
    "    sigma = [[30, 0],[0, 50]]\n",
    "    R = cholesky(sigma)\n",
    "    return np.dot(np.random.randn(count, 2), R) + mu\n",
    "\n",
    "print(noise(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x7efec8301208>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"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knxicinAbwOwNkicgLATgDjAPaKyA0AngBwbXEttIvLGhAR1RjTNURENcYgT0RUYwzyREQ1xiBPRFRjDPJERDXGIE9EVGMM8kRENfb/5wv4PQL5KRsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "noise_data = noise(basic_data.shape[0] * 5)\n",
    "data = np.vstack((noise_data, basic_data))\n",
    "plt.scatter(data[:,0], data[:,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 添加常数项"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.          3.62182647 -1.09154377]\n",
      " [ 1.         -0.85222603 -3.38196499]\n",
      " [ 1.          7.53259309  3.68855284]\n",
      " [ 1.         -0.77457761 -2.05365918]\n",
      " [ 1.         -1.86527582  6.63398165]]\n"
     ]
    }
   ],
   "source": [
    "data = np.c_[np.ones(data.shape[0]), data]\n",
    "print(data[:5])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 偏移衡量\n",
    "点到直线的距离公式\n",
    "$$\n",
    "d = \\frac{Ax + BY + C}{\\sqrt{A^2 + B^2}}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2.]\n"
     ]
    }
   ],
   "source": [
    "def distance(_point, _theta):\n",
    "    return np.abs((np.dot(_theta, _point[:-1]) - _point[-1]) / np.sqrt(_theta[1] * _theta[1] + 1))\n",
    "\n",
    "p = [[1], [2], [2]]\n",
    "t = [0, 0]\n",
    "print(distance(p, t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ransac(_data, shift_threshold, sample_count_threshold, iters):\n",
    "    best_theta = None\n",
    "    most_sample_count = 0\n",
    "    samples = None\n",
    "    ### \n",
    "    for _ in range(iters):\n",
    "        data_index = np.arange(data.shape[0])\n",
    "        sample_index = np.random.choice(data_index, 2)\n",
    "        sample_a, sample_b = _data[sample_index]\n",
    "        w = (sample_a[-1] - sample_b[-1]) / (sample_a[1] - sample_b[1])\n",
    "        b = sample_a[-1] - w * sample_a[1]\n",
    "        theta = np.array([b, w])\n",
    "        dis = distance(_data.T, theta)\n",
    "        sample_index = dis < shift_threshold\n",
    "        sample_count = len(dis[sample_index])\n",
    "        if sample_count > most_sample_count:\n",
    "            most_sample_count = sample_count\n",
    "            best_theta = theta\n",
    "            samples = _data[sample_index]\n",
    "    if most_sample_count > sample_count_threshold:\n",
    "        return best_theta, sample_count, samples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "[-3.44902942  3.44773107]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:10: RuntimeWarning: invalid value encountered in double_scalars\n",
      "  # Remove the CWD from sys.path while we load stuff.\n",
      "/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:14: RuntimeWarning: invalid value encountered in less\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "theta, sample_count, samples = ransac(data, 2, 0, data.shape[0])\n",
    "print(sample_count)\n",
    "print(theta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAD4CAYAAAAJmJb0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliL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I+AkwNfBpniuhRjq/PtFtNclIk8CL3tsjpuk/GcfC8aY7cHfO0XkRQLhqHQW+R0i0sYY87mItAF2+m2QW2i4JgIi0io0OCkiPyRQG/9jf62Km7Su8x/85wtxDYEB5nThPaCjiHQQkeYEBsAX+WxTXIjIoSLyg9BrAqvDpdO9sGIRMCT4eggN16xOa7LKk3dCRK4BHgFaAYtFZJ0xpidwAXCfiNQAtcCtxpjGgzYphd21ZECd/yki0oVAmOMT4Of+mhM9xpgaERkBLAVygKeNMRt8NitejgFeDK4IdxAw2xjzqr8mRY+IPA9cBLQUkW3APcBkYJ6IDAW2Atf5Z6G7aFkDRVGUDEbDNYqiKBmMiryiKEoGoyKvKIqSwajIK4qiZDAq8oqiKBmMiryiKEoGoyKvKIqSwfx/KK8Y3pIX2VkAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(data[:,1], data[:,-1])\n",
    "line_X = np.linspace(-10, 10, 100)\n",
    "line_Y = theta[1] * line_X + theta[0]\n",
    "plt.plot(line_X, line_Y, color='red')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
